// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'

// 导入 PermissionLayout 和子组件
import PermissionLayout from '@/views/PermissionLayout.vue'
import PermissionAssign from '@/views/PermissionAssign.vue'
import UserPermission from '@/views/UserPermission.vue'
import RolePermission from '@/views/RolePermission.vue'

const routes = [
  {
    path: '/',
    redirect: '/login' // 修改根路径重定向
  },
  {
    path: '/main',
    component: () => import('@/components/Layout.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/Home.vue')
      },
      {
        path: '/user',
        component: () => import('@/views/UserManagementLayout.vue'), // 父路由组件
        children: [
          {
            path: 'emotion',
            name: 'EmotionManagement',
            component: () => import('@/views/EmotionManagement.vue') // 情绪记录管理页面
          },
          {
            path: 'status',
            name: 'UserStatusManagement',
            component: () => import('@/views/UserManagement.vue') // 用户管理页面
          },
          {
            path: 'personalEmotion',
            name: 'PersonEmotion',
            component: () => import('@/views/PersonEmotion.vue') // 用户情绪详情管理页面
          },
          {
            path:'latestEmotion',
            name: 'LatestEmotion',  
            component: () => import('@/views/LatestEmotion.vue') // 最新情绪记录页面
          }
        ]
      },
      {
        path: '/square',
        name: 'Square',
        component: () => import('@/views/Square.vue')
      },
      {
        path: '/permission',
        component: PermissionLayout,
        children: [
          { path: 'assign', name: 'PermissionAssign', component: PermissionAssign },
          { path: 'user', name: 'UserPermission', component: UserPermission }
        ]
      },
      {
        path: '/permission/role',
        name: 'RolePermission',
        component: RolePermission
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/Test',
    name: 'test',
    component: () => import('@/views/test.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router